CheckBox
CheckBox is a UI element for toggling visibility or options on top of charts. It supports styling, positioning, and event callbacks.
Adding CheckBox
import lightningchart as lc
chart = lc.ChartXY()
checkbox = chart.add_checkbox("Show series", x=85, y=90, position_scale="percentage")
State (On/Off)
checkbox.set_on(True)
print(checkbox.get_on())
Locking
Prevent user toggling when locked.
checkbox.set_locked(True)
print(checkbox.get_locked())
Text
Set the text of the entire shape.
checkbox.set_text("Enable")
print(checkbox.get_text())
Text Styling
Set various text styles.
checkbox.set_text_fill_style("#222")
checkbox.set_text_fill_style_hidden("#999")
checkbox.set_text_font(size=14, family="Arial", weight="bold")
checkbox.set_text_rotation(0)
Button Styling
Set styles for the checkbox button.
checkbox.set_button_shape("circle")
checkbox.set_button_size(18)
checkbox.set_button_on_fill_style("#4caf50")
checkbox.set_button_off_fill_style("#f44336")
checkbox.set_button_stroke_style(thickness=1, color="#333")
Background & Stroke
Styling for the checkbox background and border.
checkbox.set_background_color("#ffffff")
checkbox.set_stroke(thickness=1, color="#cccccc")
Positioning
Cotrol the position and origin of the CheckBox.
checkbox.set_position(85, 90)
checkbox.set_origin("RightTop")
Padding & Margin
Control spacing inside and outside the CheckBox.
checkbox.set_padding(6)
checkbox.set_padding(left=8, top=6, right=8, bottom=6)
checkbox.set_margin(6)
checkbox.set_margin(left=4, right=4, top=2, bottom=2)
Pointer Events
Enable or disable mouse interactions.
checkbox.set_pointer_events(True)
Dragging
checkbox.set_dragging_mode("draggable")
Options:
draggablenotDraggableonlyHorizontalonlyVertical
Auto Dispose
Automatically dispose the CheckBox when it exceeds a viewport size threshold.
checkbox.set_auto_dispose(mode="max-width", threshold=0.2)
Options include:
max-widthmax-height
Events
Listen for checkbox state changes with the switch event.
def on_switch(event):
is_on = bool(event.get("state"))
print("ON" if is_on else "OFF")
checkbox.add_event_listener("switch", handler=on_switch)